package logic

import (
	"context"
	"yktwo/models/redis"

	"yktwo/yktworpc/internal/svc"
	"yktwo/yktworpc/yktworpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectListLogic {
	return &CollectListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 收藏
func (l *CollectListLogic) CollectList(in *yktworpc.CollectListRequest) (*yktworpc.CollectListResponse, error) {
	// todo: add your logic here and delete this line

	scores := redis.Client.ZRevRangeWithScores("collect", 0, 9)

	var ListStruct []*yktworpc.CollectListStruct

	for _, list := range scores.Val() {
		Struct := &yktworpc.CollectListStruct{
			Jsq:         int64(list.Score),
			ProduceName: list.Member.(string),
		}
		ListStruct = append(ListStruct, Struct)
	}

	return &yktworpc.CollectListResponse{Lists: ListStruct}, nil
}
